package com.ygo.feihua;

import android.graphics.*;
import android.graphics.drawable.*;
import android.os.*;
import android.support.v4.app.*;
import android.text.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.widget.AdapterView.*;
import com.ygo.feihua.adapter.*;
import com.ygo.feihua.util.*;
import java.io.*;
import java.util.*;

import android.view.View.OnClickListener;
import android.support.v7.widget.*;
import com.xiaomi.mistatistic.sdk.*;

public class WoGuanyu extends Fragment implements OnClickListener
{

	@Override
	public void onClick(View p1)
	{
		String title="";
		String message="";
		/*switch(p1.getId()){
			case R.id.gy_hr:
				title="HR工作室";
				message="因为想,所以有";
				break;
			case R.id.gy_ourygo:
				title="OURYGO";
				message="隶属于HR工作室的团队,为创造更人性化的决斗而努力";
				break;
			case R.id.gy_mc:
				title="萌立方 MoeCube";
				message="世界与我是那么格格不入，"
				+"\n我们总在搜索与我们相似的人，"
				+"\n——同道之人，同好之人，同命之人。"
				+"\n在这个一切都被沦为工具的时代，"
				+"\n呼吸似乎都变得困难。"
				+"\n孤独的我们，"
				+"\n在无尽的大海中相互取暖，"
				+"\n多么的希望有一个共同的家园啊！"
				+"\n这里,便是孤独者的家园";
				break;
			case R.id.gy_ygo233:
				title="YGOPro 233服";
				message="一个游戏王YGOPro的联机对战服务\n支持随机对战与约战，不需要注册用户。";
				break;
		}
		View[] vv=du.dialogt1(true,title,message);
		Button b1=(Button) vv[0];
		b1.setText("确定");
		b1.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					du.dis();
					// TODO: Implement this method
				}
			});*/
		
	// TODO: Implement this method
	}

	
	
    Gongju gj;
	DialogUtils du;
    private ListView gy_list;
	private TextView main_cs;
	private int tb;
    private List<String> data=new ArrayList<String>();
    
	private CardView gy_hr,gy_ourygo,gy_mc,gy_ygo233;
	
    AdapterTextview adpt;
	
	
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		// TODO: Implement this method
		
		 View v=inflater.inflate(R.layout.wo_guanyu,null);
				
					
				
		
		gj =Gongju.getdx(getActivity());
		du=DialogUtils.getdx(getActivity());
        gy_list=(ListView) v.findViewById(R.id.gy_list);
    	main_cs=(TextView) v.findViewById(R.id.main_cs);
		
		/*gy_hr=(CardView) v.findViewById(R.id.gy_hr);
		gy_ourygo=(CardView) v.findViewById(R.id.gy_ourygo);
		gy_mc=(CardView) v.findViewById(R.id.gy_mc);
		gy_ygo233=(CardView) v.findViewById(R.id.gy_ygo233);
		*/
		main_cs.setText("喵已经和我玩耍过"+SharedPreferenceUtil.getAppStartTimes()+"次啦~");
		
	/*	gy_hr.setOnClickListener(WoGuanyu.this);
		gy_ourygo.setOnClickListener(WoGuanyu.this);
		gy_mc.setOnClickListener(WoGuanyu.this);
		gy_ygo233.setOnClickListener(WoGuanyu.this);
		*/
        data.add("检查更新");
        data.add("更新履历");
        data.add("关于");
        data.add("支持我们");
		data.add("加入官方群");
		data.add("访问官网");
		data.add("加入我们");
        adpt=new AdapterTextview(getActivity(),data);
        gy_list.setAdapter(adpt);
        
        gy_list.setOnItemClickListener(new OnItemClickListener(){

                @Override
                public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
                {
                    switch(p3){
                        case 0:
							gj.show("检查更新中,请稍等");
							gj.checkUpdate(true);
							
							/*List<String> ls=new ArrayList<String>();
							for(int i=0;i<10;i++){
								ls.add("选项"+i);
							}
							du.dialogCheckbox("测试多选",ls,new ArrayList<Integer>());*/
						/*	final UserManagement um=UserManagement.getDx();
							new Thread(new Runnable(){

									@Override
									public void run()
									{
										String qx="{\"user_qx\":"+"1}";
										String ss=	BmobUtil.update("_User",um.getUser().getObjectId(),qx);
										//Gongju.show(ss);
										Log.e("返回结果","为"+ss);
										
										// TODO: Implement this method
									}
								}).start();*/
								//du.dialogMessagQuery(new int[]{DialogUtils.QUERY_CARD,DialogUtils.QUERY_DECK/*,DialogUtils.QUERY_KADIAN,DialogUtils.QUERY_ZHUTI*/},getActivity().getSupportFragmentManager());
								
							
                            break;
                        case 1:
                            
                            final List<Map<String,Object>> data=gj.getupdaterz();
                            View[] vvv=du.dialogupdaterz(true,"更新日志",data);
                            ListView li=(ListView) vvv[0];
                            Button bb1=(Button) vvv[1];

                            li.setOnItemLongClickListener(new OnItemLongClickListener(){

                                    @Override
                                    public boolean onItemLongClick(AdapterView<?> p1, View p2, int p3, long p4)
                                    {
                                        ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(getActivity().CLIPBOARD_SERVICE);
                                        cmb.setText((String)data.get(p3).get("vosin")+"\n"+data.get(p3).get("message"));//复制命令
                                        gj.show("已复制到剪贴板");

                                        // TODO: Implement this method
                                        return true;
                                    }
                                });

                            bb1.setOnClickListener(new OnClickListener(){

                                    @Override
                                    public void onClick(View p1)
                                    {
                                        du.dis();
                                        // TODO: Implement this method
                                    }
                                });
                            break;
                        
                         case 2:
                            View[] v=du.dialogt1(true,"OURYGO团队出品","相关资料来源:\n无卡面基:YGORoid\n卡片召唤词:ygo233服\n感谢大家的帮助与支持\n有什么好的建议或者bug可发邮件到2415465104@qq.com这个邮箱,谢谢");
                            Button b1=(Button) v[0];
                            b1.setOnClickListener(new OnClickListener(){

                                    @Override
                                    public void onClick(View p1)
                                    {
                                        du.dis();
                                        // TODO: Implement this method
                                    }
                                });
                             break;
                         case 3:
							tb=R.drawable.jz;
							 ListView list=(ListView) du.dialogl(false,"",new String[]{"QQ捐助","微信捐助","支付宝捐助"});
							list.setOnItemClickListener(new OnItemClickListener(){

									@Override
									public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
									{
										switch(p3){
											case 0:
												tb=R.drawable.jz_qq;
												break;
											case 1:
												tb=R.drawable.jz_weixin;
												break;
											case 2:
												tb=R.drawable.jz;
											break;
										}
										
										du.dis();
										View[] v6 =du.dialogi(true,"捐助","喵的捐助可以让我们更好的改善软件质量~\n扫描下面二维码即可进行捐助",tb);
										Button bb=(Button) v6[0];
										bb.setText("保存二维码到相册");
										bb.setOnClickListener(new OnClickListener(){

												@Override
												public void onClick(View p1)
												{
													du.dis();
													try
													{
														saveDrawableById(tb, "ourygo_zcwm.jpg",Gongju.PATH_GEN, Bitmap.CompressFormat.JPEG);
														gj.show("成功保存到"+gj.PATH_GEN+"ourygo_zcwm.jpg");
													}
													catch (IOException e)
													{
														gj.show("保存失败,原因为"+e);
													}

													//fz(,gj.PATH_GEN);
													// TODO: Implement this method
												}
											});
										// TODO: Implement this method
									}
								});
                            
                             break;
						case 4:
							gj.joinQQGroup("zv5xSt-Zu739mNbsBfZ9Qn_-esYqHaT9");
							
							
							break;
						case 5:
							startActivity(IntentUtil.getUrlIntent(getActivity(),"http://ourygo.top"));
							break;
						case 6:
							startActivity(IntentUtil.getUrlIntent(getActivity(),"http://tieba.baidu.com/p/5487883793?share=9105&fr=share&see_lz=0&sfc=copy&client_type=2&client_version=9.1.8.3&st=1513875190&unique=DB5B7BE719DA21CC143F28FF541301B3"));
							
							break;
                    }
                    // TODO: Implement this method
                }
            });
				
		
		return v;
	}
	

	@Override
	public void onResume(){
		// TODO: Implement this method
		super.onResume();
		
		MiStatInterface.recordPageStart(getActivity(), "关于");
	}

	@Override
	public void onPause(){
		// TODO: Implement this method
		super.onPause();
		MiStatInterface.recordPageEnd();
	}
	
	
	/**
     * 存储资源为ID的图片
     * @param id
     * @param name
     */
    public void saveDrawableById(int id, String name,String path,Bitmap.CompressFormat format) throws IOException {
        Drawable drawable = idToDrawable(id);
        Bitmap bitmap = drawableToBitmap(drawable);
        saveBitmap(bitmap, name,path, format);
    }

    /**
     * 将资源ID转化为Drawable
     * @param id
     * @return
     */
    public Drawable idToDrawable(int id) {
        return this.getResources().getDrawable(id);
    }

    /**
     * 将Drawable转化为Bitmap
     * @param drawable
     * @return
     */
    public Bitmap drawableToBitmap(Drawable drawable) {
        if(drawable == null)
            return null;
        return ((BitmapDrawable)drawable).getBitmap();
    }

    /**
     * 将Bitmap以指定格式保存到指定路径
     * @param bitmap
     * @param path
     */
    public void saveBitmap(Bitmap bitmap, String name,String path,Bitmap.CompressFormat format) throws FileNotFoundException, IOException {
        // 创建一个位于SD卡上的文件
        File file = new File(path,
							 name);
        FileOutputStream out = null;
     
            // 打开指定文件输出流
            out = new FileOutputStream(file);
            // 将位图输出到指定文件
            bitmap.compress(format, 100,
							out);
            out.close();
      
    }
	 
}
